home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsparamx.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.5 KB  |  176 lines

  1. /* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsparamx.c,v 1.3 2000/09/19 19:00:30 lpd Exp $ */
  20. /* Extended parameter dictionary utilities */
  21. #include "string_.h"
  22. #include "gserror.h"
  23. #include "gserrors.h"
  24. #include "gstypes.h"
  25. #include "gsmemory.h"
  26. #include "gsparam.h"
  27. #include "gsparamx.h"
  28.  
  29. /* Compare a C string and a gs_param_string. */
  30. bool
  31. gs_param_string_eq(const gs_param_string * pcs, const char *str)
  32. {
  33.     return (strlen(str) == pcs->size &&
  34.         !strncmp(str, (const char *)pcs->data, pcs->size));
  35. }
  36.  
  37. /* Put an enumerated value. */
  38. int
  39. param_put_enum(gs_param_list * plist, gs_param_name param_name,
  40.            int *pvalue, const char *const pnames[], int ecode)
  41. {
  42.     gs_param_string ens;
  43.     int code = param_read_name(plist, param_name, &ens);
  44.  
  45.     switch (code) {
  46.     case 1:
  47.         return ecode;
  48.     case 0:
  49.         {
  50.         int i;
  51.  
  52.         for (i = 0; pnames[i] != 0; ++i)
  53.             if (gs_param_string_eq(&ens, pnames[i])) {
  54.             *pvalue = i;
  55.             return 0;
  56.             }
  57.         }
  58.         code = gs_error_rangecheck;
  59.     default:
  60.         ecode = code;
  61.         param_signal_error(plist, param_name, code);
  62.     }
  63.     return code;
  64. }
  65.  
  66. /* Put a Boolean value. */
  67. int
  68. param_put_bool(gs_param_list * plist, gs_param_name param_name,
  69.            bool * pval, int ecode)
  70. {
  71.     int code;
  72.  
  73.     switch (code = param_read_bool(plist, param_name, pval)) {
  74.     default:
  75.         ecode = code;
  76.         param_signal_error(plist, param_name, ecode);
  77.     case 0:
  78.     case 1:
  79.         break;
  80.     }
  81.     return ecode;
  82. }
  83.  
  84. /* Put an integer value. */
  85. int
  86. param_put_int(gs_param_list * plist, gs_param_name param_name,
  87.           int *pval, int ecode)
  88. {
  89.     int code;
  90.  
  91.     switch (code = param_read_int(plist, param_name, pval)) {
  92.     default:
  93.         ecode = code;
  94.         param_signal_error(plist, param_name, ecode);
  95.     case 0:
  96.     case 1:
  97.         break;
  98.     }
  99.     return ecode;
  100. }
  101.  
  102. /* Put a long value. */
  103. int
  104. param_put_long(gs_param_list * plist, gs_param_name param_name,
  105.            long *pval, int ecode)
  106. {
  107.     int code;
  108.  
  109.     switch (code = param_read_long(plist, param_name, pval)) {
  110.     default:
  111.         ecode = code;
  112.         param_signal_error(plist, param_name, ecode);
  113.     case 0:
  114.     case 1:
  115.         break;
  116.     }
  117.     return ecode;
  118. }
  119.  
  120. /* Copy one parameter list to another, recursively if necessary. */
  121. int
  122. param_list_copy(gs_param_list *plto, gs_param_list *plfrom)
  123. {
  124.     gs_param_enumerator_t key_enum;
  125.     gs_param_key_t key;
  126.     int code;
  127.  
  128.     param_init_enumerator(&key_enum);
  129.     while ((code = param_get_next_key(plfrom, &key_enum, &key)) == 0) {
  130.     char string_key[256];    /* big enough for any reasonable key */
  131.     gs_param_typed_value value;
  132.     gs_param_collection_type_t coll_type;
  133.     gs_param_typed_value copy;
  134.  
  135.     if (key.size > sizeof(string_key) - 1) {
  136.         code = gs_note_error(gs_error_rangecheck);
  137.         break;
  138.     }
  139.     memcpy(string_key, key.data, key.size);
  140.     string_key[key.size] = 0;
  141.     if ((code = param_read_typed(plfrom, string_key, &value)) != 0) {
  142.         code = (code > 0 ? gs_note_error(gs_error_unknownerror) : code);
  143.         break;
  144.     }
  145.     gs_param_list_set_persistent_keys(plto, key.persistent);
  146.     switch (value.type) {
  147.     case gs_param_type_dict:
  148.         coll_type = gs_param_collection_dict_any;
  149.         goto cc;
  150.     case gs_param_type_dict_int_keys:
  151.         coll_type = gs_param_collection_dict_int_keys;
  152.         goto cc;
  153.     case gs_param_type_array:
  154.         coll_type = gs_param_collection_array;
  155.     cc:
  156.         copy.value.d.size = value.value.d.size;
  157.         if ((code = param_begin_write_collection(plto, string_key,
  158.                              ©.value.d,
  159.                              coll_type)) < 0 ||
  160.         (code = param_list_copy(copy.value.d.list,
  161.                     value.value.d.list)) < 0 ||
  162.         (code = param_end_write_collection(plto, string_key,
  163.                            ©.value.d)) < 0)
  164.         break;
  165.         code = param_end_read_collection(plfrom, string_key,
  166.                          &value.value.d);
  167.         break;
  168.     default:
  169.         code = param_write_typed(plto, string_key, &value);
  170.     }
  171.     if (code < 0)
  172.         break;
  173.     }
  174.     return code;
  175. }
  176.